package com.qf.springcloud.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.annotation.PostConstruct;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author zjw
 * @description
 * @date 2021/11/9 17:40
 */
@RestController
public class AirSearchController {

    @Autowired
    private ObjectMapper mapper;

    @Value("${server.port}")
    private int port;

    @GetMapping("/air/search")
    public String search() throws InterruptedException {
        System.out.println("1111");
        Thread.sleep(100);
        return "Hello AirSearch:" + port;
    }


    @GetMapping("/air/delete/{id}")
    public Map delete(@PathVariable String id){
        System.out.println("删除" + id + "的数据成功!");
        Map result = new HashMap();
        result.put("code",0);
        result.put("msg","");
        return result;
    }


    @PostMapping("/air/update")
    public void update(String id, String name, Integer age, Date birthday){
        String info = String.format("修改id为%s的数据，name为%s，年龄为%s，生日为" + birthday, id, name, age);
        System.out.println(info);
    }

    @PostMapping(value = "/air/add",produces = "application/json;charset=utf-8")
    public String add(@RequestBody Map map) throws JsonProcessingException {
        System.out.println("接收到数据：" + map);
        String result = mapper.writeValueAsString(map);
        return result;
    }

}
























